<?php

namespace App\Http\Requests;

use App\Http\Requests\Request;
use Illuminate\Support\Facades\Validator;

class LinksRequest extends Request
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'link_name' => 'required',
            'link_url' => 'required|url',
        ];
    }
    
    public function messages() {
        return [
            'link_name.required' => '网站名称不能为空',
            'link_url.required' => '网站链接不能为空',
            'link_url.url' => '网站链接不合法'
        ];
    }
    
    public function validateInput($data)
    {
        $message = Validator::make($data, $this->rules(), $this->messages());
        return $message->errors();
    }
}
